<html>
<head><meta charset="utf-8"><title>Extensions on dependencies · t-compiler/help · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/index.html">t-compiler/help</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Extensions.20on.20dependencies.html">Extensions on dependencies</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="240832211"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Extensions%20on%20dependencies/near/240832211" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Adrian Palacios <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Extensions.20on.20dependencies.html#240832211">(May 31 2021 at 13:15)</a>:</h4>
<p>While working on a new compiler backend, we have stumbled upon a crate that <a href="https://github.com/firecracker-microvm/firecracker/blob/main/src/vm-memory/Cargo.toml">depends on the <code>vm-memory</code> crate</a> and <a href="https://github.com/firecracker-microvm/firecracker/blob/main/src/vm-memory/src/mmap.rs#L55">extends a couple of structs</a> (and their implementations) from that crate. Our backend is having trouble with this feature since it generates code as if there were two crates, resulting in conflicts during the linking stage coming from the redefinition of these structs.</p>
<p>First, is it common to find this in Rust projects? All I could find regarding dependencies is <a href="https://doc.rust-lang.org/cargo/reference/specifying-dependencies.html">this section of the Cargo book</a>. I would to know more about how this is handled in Rust, so any pointers would be appreciated.</p>



<a name="240833170"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Extensions%20on%20dependencies/near/240833170" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Extensions.20on.20dependencies.html#240833170">(May 31 2021 at 13:23)</a>:</h4>
<p>renaming packages? yeah, that's not too common, but also not super rare</p>



<a name="240833267"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Extensions%20on%20dependencies/near/240833267" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Extensions.20on.20dependencies.html#240833267">(May 31 2021 at 13:25)</a>:</h4>
<p>but I'm not sure why this would affect a compiler backend? it just affects name resolution to my knowledge</p>



<a name="240842071"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Extensions%20on%20dependencies/near/240842071" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Adrian Palacios <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Extensions.20on.20dependencies.html#240842071">(May 31 2021 at 14:48)</a>:</h4>
<p>Thanks <span class="user-mention" data-user-id="211727">@Jonas Schievink  [he/him]</span> </p>
<p>For example, for the <code>GuestRegionMmap</code> struct being redefined our backend shows this conflict:</p>
<div class="codehilite"><pre><span></span><code>reason for conflict at #this.ptr.pointer-&gt;data: number of members is different (2/3)

struct mmap::GuestRegionMmap {
  struct mmap_unix::MmapRegion mapping;
  struct guest_memory::GuestAddress guest_base;
}
struct mmap::GuestRegionMmap {
  struct vm_memory::MmapRegion mapping;
  struct vm_memory::GuestAddress guest_base;
  struct std::option::Option&lt;bitmap::Bitmap&gt; dirty_bitmap;
}
</code></pre></div>
<p>Now that you mention it, names are definitely the main problem here:</p>
<ol>
<li>Struct names do not include the crate's name so they cannot be distinguished.</li>
<li>Members <code>mapping</code> and <code>guest_base</code> have type <code>vm_memory::*</code> which does not include renaming (i.e., the actual type should be <code>vm_memory_upstream::*</code> or the underlying type).</li>
</ol>



<a name="240842312"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Extensions%20on%20dependencies/near/240842312" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Eric Huss <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Extensions.20on.20dependencies.html#240842312">(May 31 2021 at 14:51)</a>:</h4>
<p>It sounds like you have two versions of <code>vm-memory</code> in the dependency tree, is that correct?</p>



<a name="240842433"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Extensions%20on%20dependencies/near/240842433" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Eric Huss <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Extensions.20on.20dependencies.html#240842433">(May 31 2021 at 14:52)</a>:</h4>
<p>If so, usually that is handled by symbol mangling.  Each package will have different symbols for <code>GuestRegionMmap</code> via the <code>-C metadata</code> flags being hashed into the symbol.</p>



<a name="240843461"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Extensions%20on%20dependencies/near/240843461" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Eric Huss <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Extensions.20on.20dependencies.html#240843461">(May 31 2021 at 15:02)</a>:</h4>
<p>Yea, looking at <code>firecracker</code>, there are two versions (v0.4.0 and v0.1.0, and 0.1 depends on 0.4).  Both define a <code>GuestRegionMmap</code> struct with different fields.</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>